﻿using System.Collections.Generic;
using Hidistro.Core;
using Hidistro.Core.Enums;
using Hidistro.Entities;
using Hidistro.Entities.Commodities;
using Hidistro.SaleSystem.Catalog;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using JSShop.Model;

namespace Hidistro.UI.SaleSystem.Tags
{
    public class wnxd_ProductImages : WebControl
    {
        public wnxd_ProductImages()
        {
            base.ID = "wnxd_ProductImages";
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write(this.RendHtml());
        }
        public string RendHtml()
        {
            StringBuilder builder = new StringBuilder();
            if (this.ImageInfo != null)
            {
                Juse.Interface.ProductBrowser pb = new Juse.Interface.ProductBrowser();
                List<JSShop.Model.JS_Images> list = pb.GetImageList(ImageInfo.ProductId, 1);
                if (list == null|| list.Count==0)
                {
                    return string.Empty;
                }
                string title = string.Empty;
                string alt = string.Empty;
                string keyword = this.ImageInfo.Meta_KeyWords;
                if (!string.IsNullOrEmpty(keyword))
                {
                    string[] arr = keyword.Split('|');
                    if (arr.Length == 3)
                    {
                        title = arr[1];
                        alt = arr[2];
                    }
                }
                builder.AppendFormat("<div class=\"preview-big\"><div class=\"preview-big-box\"><img src=\"{0}\" title=\"{1}\" alt=\"{2}\"></div><a class=\"preview-next\" href=\"javascript:void(0);\"></a><a class=\"preview-prev\" href=\"javascript:void(0);\"></a></div>", Globals.GetImgUrl(list[0].ThumbnailUrl410), title, alt);
                builder.Append("<div class=\"preview-nav\"><div class=\"preview-thumbs\"><ul style=\"width: 416px;\" class=\"preview-thumbs-list clf\">");
                bool ll = false;
                foreach (var item in list)
                {
                    if (item != null)
                    {
                        if (!string.IsNullOrEmpty(item.ThumbnailUrl60))
                        {
                            builder.AppendFormat("<li><a {0}href=\"javascript:void(0);\"><img src=\"{1}\"></a></li>", ll ? "" : "class=\"current\" ", Globals.GetImgUrl(item.ThumbnailUrl410));
                            ll = true;
                        }
                    }
                }
                //for (int i = 1; i <= 5; i++)
                //{
                //    PropertyInfo info = this.ImageInfo.GetType().GetProperty("ImageUrl" + i);
                //    if (info != null)
                //    {
                //        string str = info.GetValue(this.ImageInfo, null).ToString();
                //        if (!string.IsNullOrEmpty(str))
                //        {
                //            builder.AppendFormat("<li><a {0}href=\"javascript:void(0);\"><img src=\"{1}\"></a></li>", ll ? "" : "class=\"current\" ", Globals.GetImgUrl(str));
                //            ll = true;
                //        }
                //    }
                //}
                builder.Append("</ul></div></div>");
            }
            return builder.ToString();
        }
        public vw_Hishop_BrowseProductList ImageInfo { get; set; }
    }
}
